using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;

namespace DocumentManagement
{
  /// <summary>
  /// ILPData Data Object Class
  /// </summary>
  public partial class DOILPData
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the ILPData Id
		/// </summary>
		public const string RowId = "ID";

		/// <summary>
		/// The Table Column for the ILPData AccNo
		/// </summary>
		public const string RowAccNo = "AccNo";

		/// <summary>
		/// The Table Column for the ILPData BondAmt
		/// </summary>
		public const string RowBondAmt = "BondAmt";

		/// <summary>
		/// The Table Column for the ILPData OutBal
		/// </summary>
		public const string RowOutBal = "OutBal";

		/// <summary>
		/// The Table Column for the ILPData AmtPastDue
		/// </summary>
		public const string RowAmtPastDue = "AmtPastDue";

		/// <summary>
		/// The Table Column for the ILPData ValAmt
		/// </summary>
		public const string RowValAmt = "ValAmt";

		/// <summary>
		/// The Table Column for the ILPData PrePaid
		/// </summary>
		public const string RowPrePaid = "PrePaid";

		/// <summary>
		/// The Table Column for the ILPData Monthly
		/// </summary>
		public const string RowMonthly = "Monthly";

		/// <summary>
		/// The Table Column for the ILPData BondRegDate
		/// </summary>
		public const string RowBondRegDate = "BondRegDate";

		/// <summary>
		/// The Table Column for the ILPData ValDate
		/// </summary>
		public const string RowValDate = "ValDate";

		/// <summary>
		/// The Table Column for the ILPData Status
		/// </summary>
		public const string RowStatus = "Status";

		/// <summary>
		/// The Table Column for the ILPData SubStatus
		/// </summary>
		public const string RowSubStatus = "SubStatus";

		/// <summary>
		/// The Table Column for the ILPData BranchCode
		/// </summary>
		public const string RowBranchCode = "BranchCode";

		/// <summary>
		/// The Table Column for the ILPData custID
		/// </summary>
		public const string RowcustID = "custID";

		/// <summary>
		/// The Table Column for the ILPData custName1
		/// </summary>
		public const string RowcustName1 = "custName1";

		/// <summary>
		/// The Table Column for the ILPData custName2
		/// </summary>
		public const string RowcustName2 = "custName2";

		/// <summary>
		/// The Table Column for the ILPData custPersTel
		/// </summary>
		public const string RowcustPersTel = "custPersTel";

		/// <summary>
		/// The Table Column for the ILPData custBussTel
		/// </summary>
		public const string RowcustBussTel = "custBussTel";

		/// <summary>
		/// The Table Column for the ILPData custContTel
		/// </summary>
		public const string RowcustContTel = "custContTel";

		/// <summary>
		/// The Table Column for the ILPData AccountDate
		/// </summary>
		public const string RowAccountDate = "AccountDate";

		/// <summary>
		/// The Table Column for the ILPData Suburb
		/// </summary>
		public const string RowSuburb = "Suburb";

		/// <summary>
		/// The Table Column for the ILPData Stand
		/// </summary>
		public const string RowStand = "Stand";

		/// <summary>
		/// The Table Column for the ILPData Complex
		/// </summary>
		public const string RowComplex = "Complex";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spILPData_Create";
private const string m_StoredProcedureConstDelete = "spILPData_Delete";
private const string m_StoredProcedureConstRetrieve = "spILPData_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spILPData_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spILPData_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private int m_Id;
		private string m_AccNo;
		private decimal m_BondAmt;
		private decimal m_OutBal;
		private decimal m_AmtPastDue;
		private decimal m_ValAmt;
		private decimal m_PrePaid;
		private decimal m_Monthly;
		private DateTime m_BondRegDate;
		private DateTime m_ValDate;
		private string m_Status;
		private string m_SubStatus;
		private string m_BranchCode;
		private string m_custID;
		private string m_custName1;
		private string m_custName2;
		private string m_custPersTel;
		private string m_custBussTel;
		private string m_custContTel;
		private DateTime m_AccountDate;
		private string m_Suburb;
		private string m_Stand;
		private string m_Complex;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOILPData> m_ILPDatas = new List<DOILPData>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOILPData() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// Id
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData Id
		/// </remarks>
		public int Id
		{
			get { return (this.m_Id); }
			set { this.m_Id = value; }
		}

		/// <summary>
		/// AccNo
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData AccNo
		/// </remarks>
		public string AccNo
		{
			get { return (this.m_AccNo); }
			set { this.m_AccNo = value; }
		}

		/// <summary>
		/// BondAmt
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData BondAmt
		/// </remarks>
		public decimal BondAmt
		{
			get { return (this.m_BondAmt); }
			set { this.m_BondAmt = value; }
		}

		/// <summary>
		/// OutBal
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData OutBal
		/// </remarks>
		public decimal OutBal
		{
			get { return (this.m_OutBal); }
			set { this.m_OutBal = value; }
		}

		/// <summary>
		/// AmtPastDue
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData AmtPastDue
		/// </remarks>
		public decimal AmtPastDue
		{
			get { return (this.m_AmtPastDue); }
			set { this.m_AmtPastDue = value; }
		}

		/// <summary>
		/// ValAmt
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData ValAmt
		/// </remarks>
		public decimal ValAmt
		{
			get { return (this.m_ValAmt); }
			set { this.m_ValAmt = value; }
		}

		/// <summary>
		/// PrePaid
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData PrePaid
		/// </remarks>
		public decimal PrePaid
		{
			get { return (this.m_PrePaid); }
			set { this.m_PrePaid = value; }
		}

		/// <summary>
		/// Monthly
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData Monthly
		/// </remarks>
		public decimal Monthly
		{
			get { return (this.m_Monthly); }
			set { this.m_Monthly = value; }
		}

		/// <summary>
		/// BondRegDate
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData BondRegDate
		/// </remarks>
		public DateTime BondRegDate
		{
			get { return (this.m_BondRegDate); }
			set { this.m_BondRegDate = value; }
		}

		/// <summary>
		/// ValDate
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData ValDate
		/// </remarks>
		public DateTime ValDate
		{
			get { return (this.m_ValDate); }
			set { this.m_ValDate = value; }
		}

		/// <summary>
		/// Status
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData Status
		/// </remarks>
		public string Status
		{
			get { return (this.m_Status); }
			set { this.m_Status = value; }
		}

		/// <summary>
		/// SubStatus
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData SubStatus
		/// </remarks>
		public string SubStatus
		{
			get { return (this.m_SubStatus); }
			set { this.m_SubStatus = value; }
		}

		/// <summary>
		/// BranchCode
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData BranchCode
		/// </remarks>
		public string BranchCode
		{
			get { return (this.m_BranchCode); }
			set { this.m_BranchCode = value; }
		}

		/// <summary>
		/// custID
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData custID
		/// </remarks>
		public string custID
		{
			get { return (this.m_custID); }
			set { this.m_custID = value; }
		}

		/// <summary>
		/// custName1
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData custName1
		/// </remarks>
		public string custName1
		{
			get { return (this.m_custName1); }
			set { this.m_custName1 = value; }
		}

		/// <summary>
		/// custName2
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData custName2
		/// </remarks>
		public string custName2
		{
			get { return (this.m_custName2); }
			set { this.m_custName2 = value; }
		}

		/// <summary>
		/// custPersTel
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData custPersTel
		/// </remarks>
		public string custPersTel
		{
			get { return (this.m_custPersTel); }
			set { this.m_custPersTel = value; }
		}

		/// <summary>
		/// custBussTel
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData custBussTel
		/// </remarks>
		public string custBussTel
		{
			get { return (this.m_custBussTel); }
			set { this.m_custBussTel = value; }
		}

		/// <summary>
		/// custContTel
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData custContTel
		/// </remarks>
		public string custContTel
		{
			get { return (this.m_custContTel); }
			set { this.m_custContTel = value; }
		}

		/// <summary>
		/// AccountDate
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData AccountDate
		/// </remarks>
		public DateTime AccountDate
		{
			get { return (this.m_AccountDate); }
			set { this.m_AccountDate = value; }
		}

		/// <summary>
		/// Suburb
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData Suburb
		/// </remarks>
		public string Suburb
		{
			get { return (this.m_Suburb); }
			set { this.m_Suburb = value; }
		}

		/// <summary>
		/// Stand
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData Stand
		/// </remarks>
		public string Stand
		{
			get { return (this.m_Stand); }
			set { this.m_Stand = value; }
		}

		/// <summary>
		/// Complex
		/// </summary>
		/// <remarks>
		/// This property contains the ILPData Complex
		/// </remarks>
		public string Complex
		{
			get { return (this.m_Complex); }
			set { this.m_Complex = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOILPData> ILPDatas
	{
	  get { return m_ILPDatas; }
	  set { m_ILPDatas = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public DataSet Retrieve()
    {
      DataSet returnDS = new DataSet();
      sqlData = new SQLDataObject();
      sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowAccNo + "=" + this.AccNo);
      return returnDS;
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    public bool Update()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowId].ToString() != "")
			this.Id = int.Parse(dr[RowId].ToString());

		if (dr[RowAccNo].ToString() != "")
			this.AccNo = dr[RowAccNo].ToString();

		if (dr[RowBondAmt].ToString() != "")
			this.BondAmt = decimal.Parse(dr[RowBondAmt].ToString());

		if (dr[RowOutBal].ToString() != "")
			this.OutBal = decimal.Parse(dr[RowOutBal].ToString());

		if (dr[RowAmtPastDue].ToString() != "")
			this.AmtPastDue = decimal.Parse(dr[RowAmtPastDue].ToString());

		if (dr[RowValAmt].ToString() != "")
			this.ValAmt = decimal.Parse(dr[RowValAmt].ToString());

		if (dr[RowPrePaid].ToString() != "")
			this.PrePaid = decimal.Parse(dr[RowPrePaid].ToString());

		if (dr[RowMonthly].ToString() != "")
			this.Monthly = decimal.Parse(dr[RowMonthly].ToString());

		if (dr[RowBondRegDate].ToString() != "")
			this.BondRegDate = DateTime.Parse(dr[RowBondRegDate].ToString());

		if (dr[RowValDate].ToString() != "")
			this.ValDate = DateTime.Parse(dr[RowValDate].ToString());

		if (dr[RowStatus].ToString() != "")
			this.Status = dr[RowStatus].ToString();

		if (dr[RowSubStatus].ToString() != "")
			this.SubStatus = dr[RowSubStatus].ToString();

		if (dr[RowBranchCode].ToString() != "")
			this.BranchCode = dr[RowBranchCode].ToString();

		if (dr[RowcustID].ToString() != "")
			this.custID = dr[RowcustID].ToString();

		if (dr[RowcustName1].ToString() != "")
			this.custName1 = dr[RowcustName1].ToString();

		if (dr[RowcustName2].ToString() != "")
			this.custName2 = dr[RowcustName2].ToString();

		if (dr[RowcustPersTel].ToString() != "")
			this.custPersTel = dr[RowcustPersTel].ToString();

		if (dr[RowcustBussTel].ToString() != "")
			this.custBussTel = dr[RowcustBussTel].ToString();

		if (dr[RowcustContTel].ToString() != "")
			this.custContTel = dr[RowcustContTel].ToString();

		if (dr[RowAccountDate].ToString() != "")
			this.AccountDate = DateTime.Parse(dr[RowAccountDate].ToString());

		if (dr[RowSuburb].ToString() != "")
			this.Suburb = dr[RowSuburb].ToString();

		if (dr[RowStand].ToString() != "")
			this.Stand = dr[RowStand].ToString();

		if (dr[RowComplex].ToString() != "")
			this.Complex = dr[RowComplex].ToString();
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOILPData ILPData = new DOILPData();
			
					if (dr[RowId].ToString() != "")
			ILPData.Id = int.Parse(dr[RowId].ToString());

		if (dr[RowAccNo].ToString() != "")
			ILPData.AccNo = dr[RowAccNo].ToString();

		if (dr[RowBondAmt].ToString() != "")
			ILPData.BondAmt = decimal.Parse(dr[RowBondAmt].ToString());

		if (dr[RowOutBal].ToString() != "")
			ILPData.OutBal = decimal.Parse(dr[RowOutBal].ToString());

		if (dr[RowAmtPastDue].ToString() != "")
			ILPData.AmtPastDue = decimal.Parse(dr[RowAmtPastDue].ToString());

		if (dr[RowValAmt].ToString() != "")
			ILPData.ValAmt = decimal.Parse(dr[RowValAmt].ToString());

		if (dr[RowPrePaid].ToString() != "")
			ILPData.PrePaid = decimal.Parse(dr[RowPrePaid].ToString());

		if (dr[RowMonthly].ToString() != "")
			ILPData.Monthly = decimal.Parse(dr[RowMonthly].ToString());

		if (dr[RowBondRegDate].ToString() != "")
			ILPData.BondRegDate = DateTime.Parse(dr[RowBondRegDate].ToString());

		if (dr[RowValDate].ToString() != "")
			ILPData.ValDate = DateTime.Parse(dr[RowValDate].ToString());

		if (dr[RowStatus].ToString() != "")
			ILPData.Status = dr[RowStatus].ToString();

		if (dr[RowSubStatus].ToString() != "")
			ILPData.SubStatus = dr[RowSubStatus].ToString();

		if (dr[RowBranchCode].ToString() != "")
			ILPData.BranchCode = dr[RowBranchCode].ToString();

		if (dr[RowcustID].ToString() != "")
			ILPData.custID = dr[RowcustID].ToString();

		if (dr[RowcustName1].ToString() != "")
			ILPData.custName1 = dr[RowcustName1].ToString();

		if (dr[RowcustName2].ToString() != "")
			ILPData.custName2 = dr[RowcustName2].ToString();

		if (dr[RowcustPersTel].ToString() != "")
			ILPData.custPersTel = dr[RowcustPersTel].ToString();

		if (dr[RowcustBussTel].ToString() != "")
			ILPData.custBussTel = dr[RowcustBussTel].ToString();

		if (dr[RowcustContTel].ToString() != "")
			ILPData.custContTel = dr[RowcustContTel].ToString();

		if (dr[RowAccountDate].ToString() != "")
			ILPData.AccountDate = DateTime.Parse(dr[RowAccountDate].ToString());

		if (dr[RowSuburb].ToString() != "")
			ILPData.Suburb = dr[RowSuburb].ToString();

		if (dr[RowStand].ToString() != "")
			ILPData.Stand = dr[RowStand].ToString();

		if (dr[RowComplex].ToString() != "")
			ILPData.Complex = dr[RowComplex].ToString();

            this.ILPDatas.Add(ILPData);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
